import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:image_picker/image_picker.dart';
import 'package:magic_car/UI/querydataagreenment.dart';
import 'package:magic_car/authinspcter/commonwidget/my_muti_selector.dart';
import 'package:magic_car/common/nodata.dart';
import 'package:magic_car/jiance/faultcode.dart';
import 'package:magic_car/jiance/mileagepage.dart';
import 'package:magic_car/jiance/querydatarecord.dart';
import 'package:magic_car/jiance/queryhistoryresult.dart';
import 'package:magic_car/res/colors.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:magic_car/util/config.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';
import 'package:fluwx/fluwx.dart' as fluwx;

//子页面
class QuerycarinfoPage extends StatefulWidget {
  //final String queryid;

  // QuerycarinfoPage(this.queryid);

  @override
  _ChildItemViewState createState() => _ChildItemViewState();
}

class _ChildItemViewState extends State<QuerycarinfoPage> {
  List codelist = [];
  String xsz_url = "";
  TextEditingController chejia = new TextEditingController();
  var acountinfo;
  String query_id = "";
  int query_type = 0;
  bool agreen = false;
  List querytype = [];
  List querytypedesc = [];
  String typestring = "请选择";
  var selecttype = 1000;
  bool seletwxpay = false;
  Map<String, dynamic> querydesc = {'desc1': '', 'desc2': '', 'note': ''};
  String car_no = "";
  String engine_no = "";
  String userrole = "0";

  String registimg = ""; //登记证
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    fluwx.weChatResponseEventHandler.listen((res) {
      print(res);
      if (res is fluwx.WeChatPaymentResponse) {
        if (res.isSuccessful) {
          if (!seletwxpay) return;
          EasyLoading.show(status: "正在查询结果，请耐心等待...");

          //支付成功
          // Toast.show('充值成功,请点击查询在次查询', context);
          // loaddata();
          Future.delayed(Duration(seconds: 2), () {
            EasyLoading.dismiss();
            //loadpage.close();
            queryprolems(query_type, xsz_url, chejia.text, 1, 3);
          });
          //  if (query_type == "2") {
          //     //历史里程
          //     Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
          //       return new MileAgePage(query_id);
          //     }));
          //   } else if (query_type == "1") {
          //     //历史故障码
          //     Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
          //       return new FaultCodePage(query_id);
          //     }));
          //   }
        } else {
          Toast.show('支付失败', context);
        }
      }
    });
    loadbussinessinfo();
    getquerytype();

    // getqueryinfo();
  }

  //获取车商的信息
  loadbussinessinfo() async {
    Map<String, String> map = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["id"] = pref.getString('uid');

    print(map);

    HttpHelper.post(HttpHelper.API_BusinessInfo, (data) async {
      if (data != null) {
        print(data);
        print(data["info"].length.toString());
        if (data["code"].toString() == "1") {
          setState(() {
            acountinfo = data["info"];
            // balance = data["info"]["balance"];
          });
        }
      }
    }, params: map);
  }

  //弹出付款方式
  poppaytype(type, rechcek) {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Container(
            height: 120,
            child: Column(
              children: [
                Container(
                  height: 40,
                  decoration: BoxDecoration(
                      border: Border(
                          bottom:
                              BorderSide(width: 1, color: Colours.base_gray))),
                  child: Center(child: Text('付款方式')),
                ),
                InkWell(
                    onTap: () {
                      if (userrole == "1") return;
                      Navigator.pop(context);
                      queryprolems(type, xsz_url, chejia.text, rechcek, 4);
                    },
                    child: Container(
                      height: 40,
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  width: 1, color: Colours.base_gray))),
                      child: Center(
                          child: Text(
                        userrole == "1" ? '套餐付费（暂不支持）' : '套餐付费',
                        style: TextStyle(
                            color: userrole == "1" ? Colors.grey : Colors.red),
                      )),
                    )),
                InkWell(
                    onTap: () {
                      setState(() {
                        seletwxpay = true;
                      });
                      Navigator.pop(context);
                      queryprolems(type, xsz_url, chejia.text, rechcek, 3);
                    },
                    child: Container(
                      height: 40,
                      // decoration: BoxDecoration(
                      //   border: Border(bottom: BorderSide(
                      //     width: 1,color: Colours.base_gray
                      //   ))
                      // ),
                      child: Center(
                          child: Text(
                        '微信支付',
                        style: TextStyle(color: Colors.red),
                      )),
                    )),
              ],
            ),
          );
        });
  }

  //查询车辆数据
  queryprolems(type, url, vin, recheck, paytype) async {
    SharedPreferences pref = await SharedPreferences.getInstance();
    String role = pref.getString('role');
    setState(() {
      userrole = role;
    });
    print(role); //1为检测师 0 为车商
    print('${type}');
    FocusScope.of(context).requestFocus(FocusNode());
    if (!agreen) {
      //
      Toast.show("请勾选服务协议！", context);
      return;
    }
    if (url == "") {
      Toast.show("请上传行驶证", context);
      return;
    }
    if (vin == "") {
      Toast.show("请填写正确的车架号", context);
      return;
    }
    if (type == 1000) {
      Toast.show('请选择查询类型', context);
      return;
    }
    EasyLoading.show(status: "正在生成查询订单");
    Map<String, String> param = new Map();

    param["uid"] = pref.getString('uid');
    param["oid"] = '0';
    param['img'] = url;
    param['vin'] = vin;
    param['car_no'] = car_no;
    param['engine_no'] = engine_no;
    if (role == "1") {
      //检测师查询
      param['is_inspector'] = "1";
    }

    param['query_type'] = type.toString();
    if (registimg != "") {
      param['registimg'] = registimg;
    }
    if (recheck == 1) {
      param['recheck'] = "1";
    }
    if (paytype > 1) {
      param['pay_type'] = paytype.toString();
    }
    print('查询参数${param}');
    HttpHelper.post(HttpHelper.API_Bussinessquerycarinfo, (data) async {
      EasyLoading.dismiss();
      if (data != null) {
        Toast.show(data['msg'], context);
        print(data);
        if (data["code"].toString() == "1") {
          //有结果的情况，需要处理结果
          if (data["info"].containsKey('url')) {
            showDialog(
              context: context,
              builder: (BuildContext context) {
                return new AlertDialog(
                  title: new Text(
                    '请用微信扫码付款后查询，如无查询结果费用将原路返回',
                    style: TextStyle(fontSize: 14),
                  ),
                  content: new SingleChildScrollView(
                      child: new Image.network(
                    data['info']['url'],
                    width: 300,
                    height: 300,
                    fit: BoxFit.fitHeight,
                  )),
                );
              },
            );
          } else if (data["info"].containsKey('alreadcheck')) {
            //有查询历史的情况
            showDialog(
                context: context,
                builder: (BuildContext context) {
                  return new CupertinoAlertDialog(
                    actions: [
                      CupertinoDialogAction(
                          child: Text('查看'),
                          onPressed: () {
                            Navigator.pop(context);
                            if (type == 2) {
                              if (data["info"].containsKey('use_url') &&
                                  data["info"]['use_url'].toString() == "1") {
                                Navigator.of(context)
                                    .push(new MaterialPageRoute(builder: (_) {
                                  return new QueryReusltPage(data['info']['id'],
                                      data['info']['result_url']);
                                }));
                              } else {
                                //历史里程
                                Navigator.of(context)
                                    .push(new MaterialPageRoute(builder: (_) {
                                  return new MileAgePage(data['info']['id']);
                                }));
                              }
                            } else if (type == 1) {
                              //历史故障码
                              if (data["info"].containsKey('use_url') &&
                                  data["info"]['use_url'].toString() == "1") {
                                Navigator.of(context)
                                    .push(new MaterialPageRoute(builder: (_) {
                                  return new QueryReusltPage(data['info']['id'],
                                      data['info']['result_url']);
                                }));
                              } else {
                                Navigator.of(context)
                                    .push(new MaterialPageRoute(builder: (_) {
                                  return new FaultCodePage(data['info']['id']);
                                }));
                              }
                            } else {
                              Navigator.of(context)
                                  .push(new MaterialPageRoute(builder: (_) {
                                return new QueryReusltPage(data['info']['id'],
                                    data['info']['result_url']);
                              }));
                            }
                          }),
                      CupertinoDialogAction(
                        child: Text('重新查询'),
                        onPressed: () {
                          Navigator.pop(context);
                          poppaytype(type, 1);
                          // queryprolems(type, xsz_url, chejia.text, 1);
                        },
                      )
                    ],
                    content: new SingleChildScrollView(
                      child: ListBody(
                        children: [
                          Text('车辆已经查询过相关信息，是否查看历史数据'),
                        ],
                      ),
                    ),
                  );
                });
          } else if (data["info"].containsKey('cancheck')) {
            poppaytype(type, 1);
          } else if (data['info'].containsKey('package')) {
            setState(() {
              query_id = data['info']['query_id'];
              query_type = type;
            });
            var payinfo = data['info'];
            print(payinfo['prepayid']['0']);
            fluwx.payWithWeChat(
                appId: Config.wx_appid,
                partnerId: payinfo['partnerid'],
                prepayId: payinfo['prepayid']['0'],
                packageValue: payinfo['package'],
                nonceStr: payinfo['noncestr'],
                timeStamp: int.parse(payinfo['timestamp']),
                sign: payinfo['sign']);
          } else {
            if (type == 2) {
              //历史里程
              if (data["info"].containsKey('use_url') &&
                  data["info"]['use_url'].toString() == "1") {
                Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                  return new QueryReusltPage(
                      data['info']['id'], data['info']['result_url']);
                }));
              } else {
                Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                  return new MileAgePage(data['info']['queryid']);
                }));
              }
            } else if (type == 1) {
              //历史故障码
              if (data["info"].containsKey('use_url') &&
                  data["info"]['use_url'].toString() == "1") {
                Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                  return new QueryReusltPage(
                      data['info']['id'], data['info']['result_url']);
                }));
              } else {
                Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                  return new FaultCodePage(data['info']['queryid']);
                }));
              }
            } else {
              //维保和碰撞需要异步获取结果
              Toast.show("订单支付成功，请进入订单页面查看结果", context);
              Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                return new QueryOrderRecPage();
              }));

              //  Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
              //     return new QueryReusltPage(data['info']['id']);
              //   }));
            }
            // Toast.show('有结果了', context);
          }
        } else {}
      }
    }, params: param);
  }

  getqueryinfo() async {
    EasyLoading.show(status: "正在查询");
    Map<String, String> param = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    param["uid"] = pref.getString('uid');
    // param['id'] = widget.queryid;

    HttpHelper.post(HttpHelper.API_QueryHistoryinfo, (data) async {
      EasyLoading.dismiss();
      if (data != null) {
        for (var item in data['info']['problem']) {
          for (var codes in item["codeList"]) {
            codes['time'] = item['updateTime'];
          }
          codelist.addAll(item["codeList"]);
        }
        setState(() {
          codelist = codelist;
        });
      }
    }, params: param);
  }

  //识别行驶证
  scanxsz(url) {
    Toast.show('信息识别中...', context);
    Map<String, String> param = new Map();

    param['img'] = url;
    HttpHelper.post(HttpHelper.API_Scanxsz, (data) async {
      //loadpage.close();
      //loadpage.close();
      if (data != null) {
        setState(() {
          xsz_url = url;
        });
        print(data);
        Map response1 = data['Response'];

        if (response1.containsKey('FrontInfo') &&
            response1['FrontInfo'].containsKey('PlateNo')) {
          setState(() {
            car_no = response1['FrontInfo']['PlateNo'];
          });
        }
        if (response1.containsKey('FrontInfo') &&
            response1['FrontInfo'].containsKey('EngineNo')) {
          setState(() {
            engine_no = response1['FrontInfo']['EngineNo'];
          });
        }

        if (response1.containsKey('FrontInfo') &&
            response1['FrontInfo'].containsKey('Vin')) {
          chejia.text = response1['FrontInfo']['Vin'];
        } else {
          Toast.show("没有识别到相关信息", context);
        }
      }
    }, params: param);
  }

  getquerytype() {
    Map<String, String> param = new Map();

    HttpHelper.post(HttpHelper.API_Querydatatype, (data) async {
      if (data != null) {
        print(data);

        if (data["code"].toString() == "1") {
          setState(() {
            querytype = data['info']['list'];
            querytypedesc = data['info']['product'];
            querydesc = data['info']['querydesc'];
          });
        }
      }
    }, params: param);
  }

  List<Widget> menuitem(data) {
    print(data);
    List<Widget> tiles = [];
    for (int i = 0; i < data.length; i++) {
      tiles.add(Container(
        padding: EdgeInsets.only(left: 1, top: 5, right: 10, bottom: 5),
        child: ChoiceChipWidget(
          // padding: new EdgeInsets.all(10),
          boxSelectColor: Colours.app_main,
          textSelectColor: Colors.white,
          selectBorder: Border.fromBorderSide(BorderSide(
              color: Colours.app_main, width: 1, style: BorderStyle.solid)),
          boxColor: Colours.base_gray,
          textColor: Colours.text_gray,
          // selectBorder: bod,
          height: 34,

          text: data[i]["title"],
          fontSize: 12,
          selected: data[i]["select"],
          border: Border.fromBorderSide(BorderSide(
              color: Colours.base_page_color,
              width: 1,
              style: BorderStyle.solid)),

          onSelected: (selected) {
            int selectnum = 0;
            for (int k = 0; k < data.length; k++) {
              if (k != i) {
                data[k]["select"] = false;
              }
              // if (taocan_arr[i]["select"] == true) selectnum++;
            }
            // if (selectnum > 2 && data[i]["select"] == false) {
            //   Toast.show("最多选择三个");
            //   return;
            // }
            data[i]["select"] = !data[i]["select"];
            if (data[i]["select"]) {
              //选中的时候进行数据处理
              setState(() {
                typestring = data[i]["title"];
              });

              var types = data[i]['value'];
              setState(() {
                selecttype = types;
              });
            } else {
              setState(() {
                typestring = '请选择';
              });

              var types = data[i]['value'];
              setState(() {
                selecttype = 1000;
              });
            }

            setState(() {
              // formList = formList;
            });

            // saveResult(false);
            // if(data==taocan_arr){
            // setState(() {
            //   taocan_arr = taocan_arr;
            //   dianzibool = i+1;
            //   // currntProduct = data[i];
            // });
            // }else {
            //   setState(() {
            //     expresstype = data;
            //     expresstypeindex = i+1;
            //   });
            // }
          },
        ),
      ));
    }
    return tiles;
  }

  getregistimgs(type, index) async {
    var image;
    if (type == 1) {
      image = await ImagePicker.pickImage(source: ImageSource.gallery);
    } else {
      image = await ImagePicker.pickImage(source: ImageSource.camera);
    }
    if (image == null) return;
    // LoadingPage loadpage = new LoadingPage(context);
    // loadpage.show();
    // File _files = await FlutterNativeImage.compressImage(image.path);
    File _files = image;

    Map<String, String> map = new Map();
    Map imgitem;

    HttpHelper.upLoadImageNocompress(_files, (data) {
      //loadpage.close();
      print('data');
      if (data.containsKey('code')) {
        Toast.show(data['msg'], context);
      } else {
        setState(() {
          registimg = data["url"];
        });
      }
    }, params: map);
  }

  getxszimgs(type, index) async {
    var image;
    if (type == 1) {
      image = await ImagePicker.pickImage(source: ImageSource.gallery);
    } else {
      image = await ImagePicker.pickImage(source: ImageSource.camera);
    }
    if (image == null) return;
    // LoadingPage loadpage = new LoadingPage(context);
    // loadpage.show();
    // File _files = await FlutterNativeImage.compressImage(image.path);
    File _files = image;

    Map<String, String> map = new Map();
    Map imgitem;

    HttpHelper.upLoadImageNocompress(_files, (data) {
      //loadpage.close();
      print('data');
      if (data.containsKey('code')) {
        Toast.show(data['msg'], context);
      } else {
        scanxsz(data["url"]);
        //  setState(() {
        //   xsz_url = data["url"];
        // });
      }
    }, params: map);
  }

  showPicker(BuildContext context) {
    Picker picker = Picker(
        adapter: PickerDataAdapter<String>(pickerdata: querytype),
        changeToFirst: false,
        textAlign: TextAlign.left,
        textStyle: TextStyle(color: Colors.blue),
        selectedTextStyle: TextStyle(color: Colors.red),
        columnPadding: const EdgeInsets.all(8.0),
        confirmText: '确定',
        confirmTextStyle: TextStyle(color: Colors.black),
        cancelText: '取消',
        cancelTextStyle: TextStyle(color: Colors.black),
        onConfirm: (Picker picker, List value) {
          print(value.toString());
          print(picker.getSelectedValues());
          setState(() {
            typestring = picker.getSelectedValues()[0];
          });
          var index = value[0];
          var types = querytypedesc[index]['type'];
          setState(() {
            selecttype = types;
          });

          //  queryprolems(selecttype, xsz_url, chejia.text, 0, 1);

          // formList[3]['value'] = picker.getSelectedValues()[0];
          // setState(() {
          //   formList = formList;
          // });
          // type_index = value[0];
          // type_index = i;
        });

    picker.show(_scaffoldKey.currentState);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        key: _scaffoldKey,
        appBar: new AppBar(
          titleSpacing: 0,
          title: Text(
            "查询信息",
            style: TextStyle(fontSize: Config.title_size),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
        ),
        body: ListView(children: [
          Container(
            color: Colors.white,
            padding: new EdgeInsets.all(10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("点击上传行驶证"),
                Container(
                  height: 10,
                ),
                InkWell(
                    onTap: () {
                      showModalBottomSheet(
                          context: context,
                          builder: (BuildContext context) {
                            return Container(
                              height: 120,
                              child: Column(
                                children: [
                                  Container(
                                    height: 40,
                                    decoration: BoxDecoration(
                                        border: Border(
                                            bottom: BorderSide(
                                                width: 1,
                                                color: Colours.base_gray))),
                                    child: Center(child: Text('选择图片')),
                                  ),
                                  InkWell(
                                      onTap: () {
                                        Navigator.pop(context);
                                        getxszimgs(0, 1);
                                      },
                                      child: Container(
                                        height: 40,
                                        decoration: BoxDecoration(
                                            border: Border(
                                                bottom: BorderSide(
                                                    width: 1,
                                                    color: Colours.base_gray))),
                                        child: Center(
                                            child: Text(
                                          '相机',
                                          style: TextStyle(color: Colors.red),
                                        )),
                                      )),
                                  InkWell(
                                      onTap: () {
                                        Navigator.pop(context);
                                        getxszimgs(1, 1);
                                      },
                                      child: Container(
                                        height: 40,
                                        // decoration: BoxDecoration(
                                        //   border: Border(bottom: BorderSide(
                                        //     width: 1,color: Colours.base_gray
                                        //   ))
                                        // ),
                                        child: Center(
                                            child: Text('相册',
                                                style: TextStyle(
                                                    color: Colors.red))),
                                      )),
                                ],
                              ),
                            );
                          });
                    },
                    child: Center(
                      child: xsz_url == ""
                          ? Image.asset('resource/images/user/xsz.png',
                              width: 150, height: 150, fit: BoxFit.fitHeight)
                          : CachedNetworkImage(
                              imageUrl: xsz_url,
                              width: MediaQuery.of(context).size.width - 30,
                              // height: 150,
                              fit: BoxFit.fitWidth),
                    )),
                Container(
                  height: 10,
                ),
                // Text('填写车架号：'),
                Container(
                  height: 10,
                ),
                Container(
                  decoration: BoxDecoration(color: Colors.white),
                  child: new TextField(
                      controller: chejia,
                      decoration: InputDecoration(
                          contentPadding: const EdgeInsets.symmetric(
                              vertical: 4.0, horizontal: 10),
                          hintText: "车架号",
                          hintStyle: TextStyle(fontSize: 15),
                          // suffixText: "车架号",
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ))),
                ),
                Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
                    child: Container(
                      color: Colors.white,
                      height: 50,
                      child: new Row(
                        children: <Widget>[
                          Expanded(
                            child: new Padding(
                              padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                              child: RichText(
                                text: TextSpan(
                                    text: '查询类型',
                                    style: TextStyle(
                                        fontSize: 15,
                                        color:
                                            Color.fromRGBO(102, 102, 102, 1)),
                                    children: [
                                      // TextSpan(
                                      //     text: '*',
                                      //     style: TextStyle(fontSize: 14, color: Colors.red))
                                    ]),
                              ),
                            ),
                            flex: 1,
                          ),
                          Expanded(
                            child: Padding(
                                padding: new EdgeInsets.fromLTRB(10, 0, 20, 0),
                                child: Align(
                                    alignment: Alignment.centerRight,
                                    child: new GestureDetector(
                                        child: new Text(typestring),
                                        onTap: () async {
                                          FocusScope.of(context)
                                              .requestFocus(FocusNode());
                                          // showPicker(context);
                                          //  showModalBottomSheet(
                                          // context: context,
                                          // builder: (BuildContext context) {
                                          //   return showDate();
                                          // });
                                        }))),
                            flex: 2,
                          )
                        ],
                      ),
                    )),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  child: Container(
                      width: MediaQuery.of(context).size.width - 20,
                      color: Colors.white,
                      child: Wrap(
                        children: menuitem(querytypedesc),
                      )),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  child: Container(
                      width: MediaQuery.of(context).size.width - 20,
                      color: Colors.white,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          Padding(
                              padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
                              child: Text(
                                '价格说明：',
                                style: TextStyle(
                                    fontSize: 13, fontWeight: FontWeight.w800),
                              )),
                          Padding(
                              padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
                              child: Text(
                                '${querydesc['desc1']}',
                                style: TextStyle(
                                    fontSize: 12, color: Colours.bj_orange_o2),
                              )),
                          Padding(
                              padding: EdgeInsets.fromLTRB(10, 3, 10, 0),
                              child: Text(
                                '${querydesc['desc2']}',
                                style: TextStyle(
                                    fontSize: 12, color: Colours.bj_orange_o2),
                              )),
                          Padding(
                              padding: EdgeInsets.fromLTRB(10, 3, 10, 10),
                              child: Text(
                                '${querydesc['note']}',
                                style: TextStyle(
                                    fontSize: 12, color: Colours.bj_orange_o2),
                              )),
                        ],
                      )),
                ),
                // Padding(
                //   padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
                //   child: Text('上传登记证（里程和故障可不传）'),
                // ),
                // Padding(
                //   padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
                //   child: InkWell(
                //     onTap: () {
                //       showModalBottomSheet(
                //           context: context,
                //           builder: (BuildContext context) {
                //             return Container(
                //               height: 120,
                //               child: Column(
                //                 children: [
                //                   Container(
                //                     height: 40,
                //                     decoration: BoxDecoration(
                //                         border: Border(
                //                             bottom: BorderSide(
                //                                 width: 1,
                //                                 color: Colours.base_gray))),
                //                     child: Center(child: Text('选择图片')),
                //                   ),
                //                   InkWell(
                //                       onTap: () {
                //                         Navigator.pop(context);
                //                         getregistimgs(0, 1);
                //                       },
                //                       child: Container(
                //                         height: 40,
                //                         decoration: BoxDecoration(
                //                             border: Border(
                //                                 bottom: BorderSide(
                //                                     width: 1,
                //                                     color: Colours.base_gray))),
                //                         child: Center(child: Text('相机')),
                //                       )),
                //                   InkWell(
                //                       onTap: () {
                //                         Navigator.pop(context);
                //                         getregistimgs(1, 1);
                //                       },
                //                       child: Container(
                //                         height: 40,
                //                         // decoration: BoxDecoration(
                //                         //   border: Border(bottom: BorderSide(
                //                         //     width: 1,color: Colours.base_gray
                //                         //   ))
                //                         // ),
                //                         child: Center(child: Text('相册')),
                //                       )),
                //                 ],
                //               ),
                //             );
                //           });
                //     },
                //     child: Container(
                //       alignment: Alignment.centerLeft,
                //       child: registimg == ""
                //           ? Image.asset('resource/images/user/upimg.png',
                //               width: 150, height: 150)
                //           : CachedNetworkImage(
                //               imageUrl: registimg, width: 150, height: 150),
                //     ),
                //   ),
                // ),
                Padding(
                    padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
                    child: Row(
                      // crossAxisAlignment: CrossAxisAlignment.baseline,
                      children: <Widget>[
                        // Expanded(
                        //   flex: 1,
                        //   child:
                        Container(
                          alignment: new FractionalOffset(0.0, 0.0),
                          width: 20,
                          height: 20,
                          child: Checkbox(
                            activeColor: Color.fromRGBO(27, 182, 251, 1),
                            checkColor: Colors.blue,
                            value: this.agreen,
                            onChanged: (value) {
                              setState(() {
                                this.agreen = value;
                              });
                            },
                          ),
                        ),
                        // Expanded(
                        //   flex:2,
                        //   child:
                        Padding(
                            padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                            child: Container(
                                child: GestureDetector(
                              onTap: () {
                                Navigator.of(context)
                                    .push(new MaterialPageRoute(builder: (_) {
                                  return new DataAgreementPage();
                                }));
                              },
                              child: RichText(
                                text: TextSpan(
                                    text: '我已经阅读并同意',
                                    style: TextStyle(
                                        fontSize: 12,
                                        color: Color.fromRGBO(51, 51, 51, 1)),
                                    children: [
                                      TextSpan(
                                          text: '【车魔估数据查询协议】',
                                          style: TextStyle(
                                            fontSize: 12,
                                            color: Colours.app_main,
                                          ))
                                    ]),
                              ),
                            )))
                        //)
                      ],
                    )),
                new Container(
                  margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
                  width: double.infinity,
                  child: new Card(
                    color: Colours.bj_red_r2,
                    // color: Color.fromRGBO(242, 185, 20, 1),
                    elevation: 1,
                    child: new FlatButton(
                      child: new Padding(
                        padding: new EdgeInsets.all(0.0),
                        child: new Text(
                          '查询',
                          style: new TextStyle(
                              color: Colors.white, fontSize: 16.0),
                        ),
                      ),
                      onPressed: () {
                        //  poppaytype();
                        queryprolems(selecttype, xsz_url, chejia.text, 0, 1);
                      },
                    ),
                  ),
                ),
                Container(
                  height: 20,
                ),
                new Container(
                  width: double.infinity,
                  child: Center(
                    child: InkWell(
                      onTap: () {
                        Navigator.of(context)
                            .push(new MaterialPageRoute(builder: (_) {
                          return new QueryOrderRecPage();
                        }));
                      },
                      child: Text('我的查询记录',
                          style: TextStyle(color: Colours.bj_orange_o2)),
                    ),
                  ),
                  // child: new Card(
                  //   color: Colours.bj_green_g1,
                  //   // color: Color.fromRGBO(242, 185, 20, 1),
                  //   elevation: 1,
                  //   child: new FlatButton(
                  //     child: new Padding(
                  //       padding: new EdgeInsets.all(0.0),
                  //       child: new Text(
                  //         '我的查询记录',
                  //         style: new TextStyle(
                  //             color: Colors.white, fontSize: 16.0),
                  //       ),
                  //     ),
                  //     onPressed: () {
                  //       Navigator.of(context)
                  //           .push(new MaterialPageRoute(builder: (_) {
                  //         return new QueryOrderRecPage();
                  //       }));

                  //       // queryprolems(1, xsz_url, chejia.text, 0, 1);
                  //     },
                  //   ),
                  // ),
                )
              ],
            ),
          )
        ]));
  }
}
